﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Matrix.MaKaYunShang.Model.Wechat
{
    public class JsTicket
    {
        public static string getnonstr(int length)
        {
            string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            string str2 = "";
            Random random = new Random();
            for (int i = 0; i < length; i++)
            {
                int startIndex = random.Next(0, str.Length);
                str2 = str2 + str.Substring(startIndex, 1);
            }
            return str2;
        }

        public static string getSign(string nonstr, string ticket, double timestamp, string url)
        {
            string format = "jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}";
            format = string.Format(format, new object[] { ticket, nonstr, timestamp, url });
            SHA1 sha = new SHA1CryptoServiceProvider();
            byte[] bytes = new ASCIIEncoding().GetBytes(format);
            return BitConverter.ToString(sha.ComputeHash(bytes)).Replace("-", "");
        }

        public int errcode { get; set; }

        public string errmsg { get; set; }

        public int expires_in { get; set; }

        public DateTime get_time { get; set; }

        public string ticket { get; set; }
    }
}
